<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/nprogress/0.2.0/nprogress.css" rel="stylesheet">
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/nprogress/0.2.0/nprogress.js"></script>
</head>

<body>
    <input type="text" id="ipt">
    <button id="btn">提交</button>
    <button id="cancel">取消请求</button>
    <script>
        let myaxios = axios.create({
            baseURL: '/',
            timeout: 10000,
            headers: {},
        })
        let ipt = document.querySelector('ipt')
        let btn = document.querySelector('btn')
        let cancel = document.querySelector('cancel')
        const CancelToken = axios.CancelToken;
        let cancel1;
        btn.onclick = async function () {
            let iptValue = ipt.value
            try {
                let result = await myaxios.get('/userLazy', {
                    params:{
                        userid:'001'
                    },
                    cancelToken: new CancelToken((c) => {
                        cancel1 = c
                    })
                })
                console.log(result);
            } catch (e) {
               console.log(e.message);
            }
        }
        // cancel the request
        cancel.onclick = function () {
            cancel()
        }
    </script>
</body>

</html>